import {
  getHomeList,
  getTabList,
  getBannerList,
  getCurrentCity,
  getVadioList,
  getMessage
} from "@/api/home.js";

const state = {
  rankCategoryList: [], ////首页Tab切换数据
  dataList: [], //获取tab切换页的数据
  carouselList: [],
  currentCity: [],
  videoList: [],
  message:[]

};

const mutations = {
  //首页Tab切换数据
  getHomeLists(state, payload) {
    state.rankCategoryList = payload;
  },

  //获取tab切换页的数据
  getTabLists(state, payload) {
    state.dataList = payload;
  },

  //获取轮播图数据
  getBannerLists(state, payload) {
    state.carouselList = payload;
  },

  //获取当前城市数据
  getCurrentCitys(state, payload) {
    state.currentCity = payload;
  },

  //获取视频数据
  getVideoLists(state, payload) {
    state.vadioList = payload;
  },
  getMessage(state,val){
    state.message = val;
  }
};

const actions = {
  //首页Tab切换数据
  async getHomeLists({ commit }, params) {
    let result = await getHomeList(params);

    commit("getHomeLists", result.rankCategoryList);
  },

  //获取tab切换页的数据
  async getTabLists({ commit }, params) {
    let result = await getTabList(params);
    commit("getTabLists", result.dataList);
  },

  //获取轮播图数据
  async getBannerLists({ commit }, params) {
    let result = await getBannerList(params);
    commit("getBannerLists", result.carouselList);
  },

  //获取当前城市数据
  async getCurrentCitys({ commit }, params) {
    let result = await getCurrentCity(params);
    commit("getCurrentCitys", result.dataList);
  },

  //获取视频数据
  async getVideoLists({ commit }, params) {
    let result = await getVadioList(params);

    console.log(result);

    commit("getVideoLists", result.dataList);
  },
  //消息
  async getMessage({ commit },val){
    console.log(val);
    let result = await getMessage(val);
    console.log(result,'消息')
    commit("getMessage",result.dataList)
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
